
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Training.java
 *
 * Created on Jan 14, 2012, 3:10:24 PM
 */
/**
 *
 * @author Figueroa
 */
public class Training extends javax.swing.JApplet implements ContainerListener{

    /** Initializes the applet Training */
    @Override
    public void init() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Training.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Training.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Training.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Training.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the applet */
      
         initComponents();
          config  = new TrainingSetup();
          this.setSize(850, 450);
          mainPanel.add(config,null);
          mainPanel.addContainerListener(this);
          player = getParameter("Player");
         // JOptionPane.showMessageDialog(null,player);
                    
    }
    public String player = "admin"; 
 //Carga el panel de juego
    public void load_play(){
     
       play = new TrainingPanel();
      play.setSize(850, 450);
      mainPanel.add(play,0);
      mainPanel.setSize(play.getSize()); 
      this.setSize(870, 500);
      play.ExcerciseList=config.ExcercisesList;
      play.player = player;
      mainPanel.revalidate();
      mainPanel.repaint();
      play.load_excercise(play.ExcerciseList.get(0),config.tiempo);
      return;
     
    }
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();

        getContentPane().setLayout(new java.awt.CardLayout());
        getContentPane().add(mainPanel, "card2");
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel mainPanel;
    // End of variables declaration//GEN-END:variables
  public TrainingSetup config;
  public TrainingPanel play;

    @Override
    public void componentAdded(ContainerEvent e) {
       // throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void componentRemoved(ContainerEvent e) {
        mainPanel.repaint();
        if(config.done){
        System.out.println(config.tiempo);
        load_play();
        config.done = false;
        }
        else{
          config  = new TrainingSetup();
          this.setSize(600, 400);
          mainPanel.add(config,null);
        }
        
    }

}
